package com.example.gateway.result;


import com.example.gateway.util.ResultCodeEnum;
import lombok.Builder;
import lombok.Getter;

/**
 * @author yangbingquan
 * @version 1.0
 * @date 2021/5/11 15:10
 */
@Getter
@Builder
public class BaseResult<T> {
    /**
     * 状态码
     */
    private int status;

    /**
     * 信息
     */
    private String message;

    /**
     * 数据
     */
    private T data;


    public static <T> BaseResult<T> success() {
        return success(ResultCodeEnum.SUCCESS, null);
    }


    public static <T> BaseResult<T> success(T data) {
        return success(ResultCodeEnum.SUCCESS, data);
    }

    public static <T> BaseResult<T> success(int status, String message) {
        return success(status, message, null);
    }

    public static <T> BaseResult<T> success(int status, String message, T data) {
        return BaseResult.<T>builder()
                .status(status)
                .message(message)
                .data(data)
                .build();
    }

    public static <T> BaseResult<T> success(ResultCodeEnum codeEnum, T data) {
        return BaseResult.<T>builder()
                .status(codeEnum.getStatus())
                .message(codeEnum.getMessage())
                .data(data)
                .build();
    }


    public static <T> BaseResult<T> error() {
        return error(ResultCodeEnum.ERROR);
    }

    public static <T> BaseResult<T> error(T data) {
        return BaseResult.<T>builder()
                .status(ResultCodeEnum.ERROR.getStatus())
                .message(ResultCodeEnum.ERROR.getMessage())
                .data(data)
                .build();
    }

    public static <T> BaseResult<T> error(int status, String message) {
        return BaseResult.<T>builder()
                .status(status)
                .message(message)
                .build();
    }

    public static <T> BaseResult<T> error(ResultCodeEnum codeEnum) {
        return BaseResult.<T>builder()
                .status(codeEnum.getStatus())
                .message(codeEnum.getMessage())
                .build();
    }

}
